# Doozer++ is (C) Copyright 2000-2010 by Iowa State University
# Distributed under the GNU Lesser General Public License 2.1.  (See
# accompanying file COPYING.txt or http://www.gnu.org/copyleft/lesser.txt)
#
# Original Author:
#   Patrick Hartling

# VR Juggler is (C) Copyright 1998, 1999, 2000, 2001 by Iowa State University
#
# Original Authors:
#   Allen Bierbaum, Christopher Just,
#   Patrick Hartling, Kevin Meinert,
#   Carolina Cruz-Neira, Albert Baker
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

# =============================================================================
# This file <dpp.obj-subdir.mk> is intended to be used by makefiles that need
# to build object files AND to recurse into subdirectories.  It defines
# variables and targets that are common to all such makefiles.  It also
# includes other .mk files that are typically necessary for this process.
# -----------------------------------------------------------------------------
# The makefile including this file must define the following variables:
#
# srcdir                   - The directory containing the source files to
#                            compile.
# OBJEXT                   - The suffix used for object files (usually .o or
#                            .obj).
# SRCS                     - The C/C++/Objective-C/Objective-C++ sources to be
#                            compiled.
# JAVA_SRCS                - The Java sources to be compiled.
# MKINSTALLDIRS            - Path to shell script for making directories.
# C_WARNS_LEVEL_0          - C warning level 0.  This would disable warnings.
# C_WARNS_LEVEL_[1-5]      - C warning levels 1 through 5.  Each level should
#                            be more strict than the previous.
# CXX_WARNS_LEVEL_0        - C++ warning level 0.  This would disable warnings.
# CXX_WARNS_LEVEL_[1-5]    - C++ warning levels 1 through 5.  Each level should
#                            be more strict than the previous.
# OBJC_WARNS_LEVEL_0       - Objective-C warning level 0.  This would disable
#                            warnings.
# OBJC_WARNS_LEVEL_[1-5]   - Objective-C warning levels 1 through 5.  Each
#                            level should be more strict than the previous.
# OBJCXX_WARNS_LEVEL_0     - Objective-C++ warning level 0.  This would disable
#                            warnings.
# OBJCXX_WARNS_LEVEL_[1-5] - Objective-C++ warning levels 1 through 5.  Each
#                            level should be more strict than the previous.
#
# Optionally, it can define the following variables for added functionality:
#
# EXTRA_SRCS_PATH - Directories besides $(srcdir) where source files may be
#                   found.
# OBJDIR          - The directory where the object files will go.  This
#                   defaults to the current directory.
# WARNS           - The warning level for all compiled code.  If not specified,
#                   the warning level defaults to 0 (no warnings).
# C_WARNS         - The warning level for C code.  If not specified, this
#                   defaults to the value of $(WARNS).
# CXX_WARNS       - The warning level for C++ code.  If not specified, this
#                   defaults to the value of $(WARNS).
# OBJC_WARNS      - The warning level for Objective-C code.  If not specified,
#                   this defaults to the value of $(WARNS).
# OBJCXX_WARNS    - The warning level for Objective-C++ code.  If not
#                   specified, this defaults to the value of $(WARNS).
# IDL_CPP_SRCS    - The C++ source files generated by the IDL compiler that
#                   need to be compiled with the other sources.
# IDL_JAVA_SRCS   - The Java source files generated by the Java IDL compiler
#                   that need to be compiled with the other sources.
# =============================================================================

ifdef BASE_OBJDIR
   OBJDIR=	$(BASE_OBJDIR)
else
   OBJDIR?=	.
endif

ifneq ($(OBJDIR), .)
   ifdef SUBOBJDIR
      OBJDIR:=	$(OBJDIR)/$(SUBOBJDIR)
   endif
endif

# Set the default warning levels for C, C++, Objective-C, and Objective-C++.
# The variable $(WARNS) is for coarse-grained settings.
WARNS?=		0
C_WARNS?=	$(WARNS)
CXX_WARNS?=	$(WARNS)
OBJC_WARNS?=	$(WARNS)
OBJCXX_WARNS?=	$(WARNS)

C_WARNS_FLAGS=		$(C_WARNS_LEVEL_$(C_WARNS))
CXX_WARN_FLAGS=		$(CXX_WARNS_LEVEL_$(CXX_WARNS))
OBJC_WARN_FLAGS=	$(OBJC_WARNS_LEVEL_$(OBJC_WARNS))
OBJCXX_WARN_FLAGS=	$(OBJCXX_WARNS_LEVEL_$(OBJCXX_WARNS))

vpath %.h $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.hh $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.H $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.c $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.C $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.CC $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.cc $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.cpp $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.c++ $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.cxx $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.m $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.mm $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.M $(srcdir) $(EXTRA_SRCS_PATH)
vpath %.$(OBJEXT) $(OBJDIR)
vpath %.java $(srcdir) $(EXTRA_JAVA_SRCS_PATH)
vpath %.class $(srcdir) $(CLASSDIR)

# Define the list of supported source file suffixes.
_suffix_list=	c C CC cc cpp c++ cxx m mm M

makeobjs=	$(filter %.$(OBJEXT), $(foreach _suffix, $(_suffix_list), $(1:.$(_suffix)=.$(OBJEXT))))

BASIC_OBJECTS=	$(call makeobjs, $(IDL_CPP_SRCS)) $(call makeobjs, $(SRCS))
BASIC_CLASSES=	$(IDL_JAVA_SRCS:.java=.class) $(JAVA_SRCS:.java=.class)

OBJECTS=	$(addprefix $(OBJDIR)/, $(BASIC_OBJECTS))
CLASSES=	$(addprefix $(OBJDIR)/, $(BASIC_CLASSES))

do-build: $(OBJECTS) $(TARGETS)

do-java-build: $(CLASSES) $(JAVA_TARGETS)

do-beforebuild:
	@$(SHELL) $(MKINSTALLDIRS) $(OBJDIR)
